<?php
namespace controller;
use model\Query;
class SocketController {
	private $question_id;
	private $query;
	public function __construct() {
		$this->query = new Query();
	}
	public function getQuestionMessage($game_id, $type) {
		$question = $this->query->getQuestionType1($game_id, $type);
		$this->question_id = $question['question_id'];
		$this->query->insertQuestionAsked($game_id, $this->question_id);		
		$message = '{"type": "question", "text": "' . $question['question_text'] . '"';
		if ($type == 1) {
			$answers = $this->query->getAnswers($question['question_id']);
			if (sizeof($answers) == 4) {
				$message .= ', "answer": [ {"answer_text": "' . $answers[0]['answer_text'] . '", "answer_id" : "' . $answers[0]['answer_id'] . '"}';
				for($i = 1; $i < sizeof ( $answers ); $i ++) {
					$message .= ', {"answer_text": "' . $answers[$i]['answer_text'] . '", "answer_id" : "' . $answers[$i]['answer_id'] . '"}';
				}
				$message .= ']}';
			} else {
				echo "Ima greshka"; // To do: throw some exceeption
			}
		} else {
			$message .= '}';
		}
		return $message;
	}
	public function getQuestionId() {
		return $this->question_id;
	}
	public function getCorrectAnswer($question_id) {
		return $this->query->getCorrectAnswer($question_id);
	}
}